package com.scalosoft.action.validation;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.validation.SkipValidation;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.VisitorFieldValidator;

@SuppressWarnings("serial")
@Namespace(value = "/validation")

/*
 * @Validation è depreato e non serve
 * @VisitorFieldValidator da spcificare nel action
 * nel Bean
 * @RequiredStringValidator per le stringhe
 * @RequiredFieldValidator per altri
 *
 */

public class ValidationAction extends ActionSupport {
	
	private static final Log log = LogFactory.getLog(ValidationAction.class);
	
	private Pagamento pagamento = new Pagamento();
	
	@VisitorFieldValidator
	public Pagamento getPagamento() {
		return pagamento;
	}

	public void setPagamento(Pagamento pagamento) {
		this.pagamento = pagamento;
	}
	

	@Action(value="validation" , results={
			@Result(name="success", location="/validation/validation-success.jsp"),
			@Result(name="input", location="/validation/validation-input.jsp")
	})
	public String execute() {
		log.debug("Simple action");
		log.debug("data :" + pagamento);
		return "success";
	}
	
	@SkipValidation
	@Action(value="init" , results={
			@Result(name="success", location="/validation/validation-input.jsp")
	})
	public String init() {
		return SUCCESS;
	}

	public void validate() {
		
	}
	
}
